package com.lams.service.archive.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.lams.jdbc.IBaseDAO;
import com.lams.jdbc.QueryUtils;
import com.lams.service.BaseFacade;
import com.lams.service.archive.IUnitFacade;
import com.lams.util.TreeEntity;

public class UnitFacade extends BaseFacade implements IUnitFacade {
	
	private  String findOrgByPar;
	
	public String getFindOrgByPar() {
		return findOrgByPar;
	}


	public void setFindOrgByPar(String findOrgByPar) {
		this.findOrgByPar = findOrgByPar;
	}

	@Override
	public List<TreeEntity> findUnitTreeByParOrgNo(String parUnitId) {
		Map params = new HashMap();
		params.put("PAR_ORG_NO", parUnitId);
		String sql = QueryUtils.getSqlBySqlCode(findOrgByPar, params);
		List<Map> list = QueryUtils.executeQuery(sql);
		//List<SOrg> list = ud.findUnitByParOrgNo(parUnitId);
		List<TreeEntity> trees = new ArrayList<TreeEntity>();
		for(Map item:list){
			TreeEntity node = new TreeEntity(String.valueOf(item.get("ORG_NO")),String.valueOf(item.get("ORG_NAME")));
			List<TreeEntity> temp = findUnitTreeByParOrgNo(String.valueOf(item.get("ORG_NO")));
			if(temp.size()==0){
				node.setLeaf(true);
			}else{
				node.setExpanded(true);
				node.setChildren(temp);
			}
			trees.add(node);
		}
		return trees;
	}
}
